import sys
import datetime

# 定义日志级别
LOG_LEVELS = {
    'DEBUG': 0,
    'INFO': 1,
    'WARN': 2,
    'ERROR': 3,
    'CRITICAL': 4
}


class Logger:
    def __init__(self, level):
        self.current_log_level = LOG_LEVELS[level]

    def log_message(self, level, *args, **kwargs):
        timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        log_entry = f"[{level}] [{timestamp}] - " + " ".join(map(str, args))
        if kwargs:
            log_entry += " " + " ".join([f"{key}={value}" for key, value in kwargs.items()])
        if LOG_LEVELS[level] >= self.current_log_level:
            print(log_entry, file=sys.stdout)

    def debug(self, *args, **kwargs):
        self.log_message('DEBUG', args, kwargs)

    def info(self, *args, **kwargs):
        self.log_message('INFO', *args, **kwargs)

    def warn(self, *args, **kwargs):
        self.log_message('WARN', *args, **kwargs)

    def error(self, *args, **kwargs):
        self.log_message('ERROR', *args, **kwargs)

    def critical(self, *args, **kwargs):
        self.log_message('CRITICAL', *args, **kwargs)


log = Logger("INFO")
